/*
** Copyright (C) 2009 Joshua Brent Marsh <joshua@icub3d.com>
** 
** This file is part of icub3d-adt
**
** icub3d-adt is free software; you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation; either version 3 of the License, or
** (at your option) any later version.
**  
** This program is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
** GNU General Public License for more details.
**  
** You should have received a copy of the GNU General Public License
** along with this program; if not, write to the Free Software
** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
**  
*/

/* $Id$ */

#ifndef ICUB3D_THREAD_POOL_H
#define ICUB3D_THREAD_POOL_H 1

#ifdef HAVE_CONFIG_H
#include <config.h>
#endif

#include <pthread.h>

#include "vector.h"
#include "pqueue.h"

typedef
struct thread_pool
{
  int stopped;
  int stopping;
  size_t num_threads;
  pthread_t *threads;
  pthread_mutex_t queue_lock;
  pthread_cond_t empty_queue;
  PQueue *work_queue;
} ThreadPool;

typedef void (work_func) (void *);

ThreadPool * thread_pool_create (size_t threads);

void thread_pool_start (ThreadPool *tp);
void thread_pool_stop (ThreadPool *tp, int remaining);

void thread_pool_destroy (ThreadPool *tp, int remaining);

int thread_pool_enqueue (ThreadPool *tp, size_t priority, 
			 work_func *wfunc, void *param);

#endif /* ICUB3D_THREAD_POOL_H */
